// 订单服务

const orderServicesModel = require("../model/orderServicesModel");
const shopsModel = require("../model/shopsModel");
const servicesModel = require('../model/servicesModel')
const usersModel = require('../model/usersModle');
const adminModel = require('../model/adminModle');



//增加匹配 
module.exports.insert = async function (content) {
    return await orderServicesModel.create(content);
}


//删除匹配
module.exports.delete = async function (id) {
    return await orderServicesModel.deleteOne({ _id: id });
}

//修改匹配
module.exports.update = async function (id, content) {
    return await orderServicesModel.updateOne({ _id: id }, content);
}

//分页所有/条件查询
module.exports.findAll = async function (searchObj, page) {
    console.log(searchObj);
    let { current, size } = page;
    let total = await orderServicesModel.countDocuments(searchObj);
    let totalPage = Math.ceil(total / size);
    let rows = await orderServicesModel.find(searchObj)
    .populate({ path: 'shopId' })
    .populate({ path: 'userId' })
    .populate({ path: 'serviceId' })
    .populate({ path: 'adminId' })
    .limit(parseInt(size))
    .skip((current - 1) * size);
    return { current, size, total, totalPage, rows };
}

// //分页所有/条件查询
// module.exports.findAllColl = async function (searchObj, page) {
//     console.log(searchObj);
//     let { current, size } = page;
//     let total = await orderServicesModel.countDocuments(searchObj);
//     let totalPage = Math.ceil(total / size);
//     let rows = await orderServicesModel.find({searchObj}).populate("serviceId").limit(parseInt(size)).skip((current - 1) * size);
//     return { current, size, total, totalPage, rows };
// }



// module.exports.finds = function () {
//     return orderServicesModel.find({}).populate('services');
    
// }

















